home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / perlref-.001 / perlref-~ / perlref-5.001.2 / refbase.tex < prev    next >
Encoding:
Text File  |  1996-01-13  |  55.3 KB  |  1,970 lines

  1. \def\revision{2}
  2. \documentclass{refbase}
  3.  
  4. \begin{document}
  5.  
  6. \begin{titlepage}
  7. \hbox{ }
  8. \end{titlepage}
  9.  
  10. \begin{titlepage}
  11. \addtolength{\evensidemargin}{2cm}
  12. \addtolength{\textwidth}{-2.1cm}
  13. \hbox{~}
  14. \addvspace{22mm}
  15.  
  16. \unnumbered{Perl Reference Guide}
  17. {\bf for Perl version \perlrev}
  18.  
  19. \vfill
  20. Perl program designed and created by Larry Wall\\
  21. |<lwall@netlabs.com>|
  22.  
  23. \vfill
  24. Reference guide designed and created by Johan Vromans\\
  25. |<jvromans@squirrel.nl>|
  26.  
  27. \vfill%addvspace{13mm}
  28. \unnumbered{Contents}
  29.  
  30. \tableofcontents
  31. \vfill
  32. {\small {Rev. \refrev}}
  33. \end{titlepage}
  34. \clearpage
  35. \setcounter{page}{2}
  36.  
  37. \unnumbered{Conventions}
  38.  
  39. \begin{enum}{2cm}
  40. \Xi{|fixed|} denotes literal text.
  41.  
  42. \Xi{<this>} means variable text, i.e. things you must fill in.
  43.  
  44. \Xi{<this>\dag} means that <this> will default to |$_| if omitted.
  45.  
  46. \Xi{\kwd{word}} is a keyword, i.e. a word with a special meaning.
  47.  
  48. \Xi{\fbox{<ret>}} denotes pressing a keyboard key.
  49.  
  50. \Xi{[\ldots]} denotes an optional part.
  51.  
  52. \end{enum}
  53.  
  54.  
  55. \section{Command line options} 
  56.  
  57. \begin{enum}{1cm}
  58.  
  59. \Xi{|-a|} turns on autosplit mode when used with |-n| or
  60. |-p|. Splits to |@F|.
  61.  
  62. \Xi{|-c|} checks syntax but does not execute.
  63.  
  64. \Xi{|-d|} runs the script under the debugger. Use `|-de 0|' to
  65. start the debugger without a script.
  66.  
  67. \Xi{|-D| <number>} sets debugging flags. 
  68.  
  69. \Xi{|-e| <commandline>} to enter a single line of
  70. script. Multiple |-e| commands may be given to build up a
  71. multi-line script.
  72.  
  73. \Xi{|-F| <regexp>} specifies a regular expression to split on 
  74. if |-a| is in effect.
  75.  
  76. \Xi{|-i| <ext>} files processed by the |<|\,|>| construct are
  77. to be edited in-place.
  78.  
  79. \Xi{|-I| <dir>} with |-P|: tells the C preprocessor where
  80. to look for include files. The directory is prepended to |@INC|.
  81.  
  82. \Xi{|-l| [ <octnum> ] } enables automatic line ending processing, 
  83. e.g. |-l013|.
  84.  
  85. \Xi{|-n|} assumes an input loop around the script. Lines are not
  86. printed.
  87.  
  88. \Xi{|-p|} assumes an input loop around the script. Lines are
  89. printed.
  90.  
  91. \Xi{|-P|} runs the C preprocessor on the script before
  92. compilation by Perl.
  93.  
  94. \Xi{|-s|} interprets `|-xxx|' on the command line as
  95. switches and sets the corresponding variables \$|xxx| in the script.
  96.  
  97. \Xi{|-S|} uses the |PATH| environment variable to search for
  98. the script.
  99.  
  100. \Xi{|-T|} forces \textit{taint} checking.
  101.  
  102. \Xi{|-u|} dumps core after compiling the script. To be used with
  103. the {\it undump\/} program (where available).
  104.  
  105. \Xi{|-U|} allows Perl to perform unsafe operations.
  106.  
  107. \Xi{|-v|} prints the version and patchlevel of your Perl
  108. executable.
  109.  
  110. \Xi{|-w|} prints warnings about possible spelling errors and
  111. other error-prone constructs in the script.
  112.  
  113. \Xi{|-x| [ <dir> ]} extracts Perl program from the input stream.
  114. If <dir> is specified, switches to this directory before running 
  115. the program.
  116.  
  117. \Xi{|-0| <val>} (that's the number zero) designates an
  118. initial value for the record separator \$|/|.
  119. See also |-l|.
  120.  
  121. \end{enum}
  122.  
  123.  
  124. \section{Literals} 
  125.  
  126. Numeric: |123  1_234  123.4  5E-10  0xff| (hex)|  0377| (octal).
  127.  
  128. \hangindent=2cm\hangafter=1
  129. String: |'abc'| literal string, no variable interpolation nor
  130. escape characters, except |\'| and |\\|. Also: |q/abc/|.
  131. Almost any pair of delimiters can be used instead of |/|\ldots|/|.
  132.  
  133. \hangindent=2cm\hangafter=1
  134. \makebox[1cm]{}|"abc"|
  135. Variables are interpolated and escape sequences are processed. 
  136. \newline Also: |qq/abc/|.
  137. \newline Escape sequences: |\t| (Tab), |\n| (Newline), |\r| (Return),
  138. |\f| (Formfeed), |\b| (Backspace), |\a| (Alarm), |\e|
  139. (Escape), |\033|(octal), |\x1b|(hex), |\c[| (control).
  140. \newline |\l| and |\u| lowcase/upcase the following character; 
  141. \newline |\L| and |\U| lowcase/upcase until a |\E| is encountered.
  142. \newline |\Q| quote regexp characters until a |\E| is encountered.
  143.  
  144. \hangindent=2cm\hangafter=1
  145. \makebox[1cm]{}|`|<command>|`|
  146. evaluates to the output of the <command>. 
  147. \newline Also: |qx/|<command>|/|.
  148.  
  149. \hangindent=1cm\hangafter=1
  150. Array: |(1,2,3)|. |()| is an empty array.  
  151. \newline |(1..4)| is the same as |(1,2,3,4)|. Likewise |('abc'..'ade')|.
  152. \newline |qw/foo bar| \ldots|/| is the same as |('foo','bar',|\ldots|)|.
  153.  
  154. \hangindent=1cm\hangafter=1
  155. Array reference: |[1,2,3]|.
  156.  
  157. \hangindent=1cm\hangafter=1
  158. Hash (associative array):
  159. |(|<key1>|, |<val1>|, |<key2>|, |<val2>|, |\ldots|)|.
  160. \newline Also: 
  161. |(|<key1>| => |<val1>|, |<key2>| => |<val2>|, |\ldots|)|.
  162.  
  163. \hangindent=1cm\hangafter=1
  164. Hash reference:
  165. |{|<key1>|, |<val1>|, |<key2>|, |<val2>|, |\ldots|}|.
  166.  
  167. \hangindent=1cm\hangafter=1
  168. Code reference:
  169. \kwd{sub} |{| <statements> |}|
  170.  
  171. \hangindent=1cm\hangafter=1
  172. Filehandles: |STDIN|, |STDOUT|, |STDERR|, |ARGV|, |DATA|.
  173. \newline User-specified: <handle>, |$|<var>.
  174.  
  175. \hangindent=1cm\hangafter=1
  176. Globs: |<|<pattern>|>| evaluates to all filenames according
  177. to the pattern.
  178. \newline Use `|<${|<var>|}>|' or `\kwd{glob} \$<var>' to glob from a variable.
  179.  
  180. \hangindent=1cm\hangafter=1
  181. Here-Is: |<<|<identifier>
  182. \quad {\it See the Perl manual for details.}
  183.  
  184. \hangindent=1cm\hangafter=1
  185. Special tokens:
  186. \newline \_\,\_|FILE|\_\,\_: filename; \_\,\_|LINE|\_\,\_: line number.
  187. \newline \_\,\_|END|\_\,\_: end of program; remaining lines can be read using
  188. \<<data>\>.
  189.  
  190.  
  191. \section{Variables} 
  192.  
  193. \begin{enum}{3.2cm}
  194.  
  195. \Xi{|\$var|} a simple scalar variable.
  196.  
  197. \Xi{|\$var[28]|} 29th element of array |@var|.
  198.  
  199. \Xi{|\$p = \char`\\@var|} now |$p| is a reference to array |@var|.
  200.  
  201. \Xi{|\$\$p[28]|} 29th element of array referenced by |$p|. 
  202. Also: |$p->[28]|.
  203.  
  204. \Xi{|\$var[-1]|} last element of array |@var|.
  205.  
  206. \Xi{|\$var[\$i][\$j]|} |$j|-th element of |$i|-th element of array |@var|.
  207.  
  208. \Xi{|\$var\{'Feb'\}|} a value from `hash' (associative array) |%var|.
  209.  
  210. \Xi{|\$p = \char`\\\%var|} now |$p| is a reference to hash |%var|.
  211.  
  212. \Xi{|\$\$p\{'Feb'\}|} a value from hash referenced by |$p|. 
  213. Also: |$p->{'Feb'}|.
  214.  
  215. \Xi{|\$\#var|} last index of array |@var|.
  216.  
  217. \Xi{|@var|} the entire array;
  218. \\
  219. in a scalar context: the number of elements in the array.
  220.  
  221. \Xi{|@var[3,4,5]|} a slice of array |@var|.
  222.  
  223. \Xi{|@var\{'a','b'\}|} a slice of |%var|; same as
  224. |($var{'a'},$var{'b'})|.
  225.  
  226. \Xi{|\%var|} the entire hash;
  227. \\
  228. in a scalar context: \true{} if the hash has elements.
  229.  
  230. \Xj{|\$var\{'a',1,...\}|} emulates a multi-dimensional array.
  231.  
  232. \Xj{|('a'..'z')[4,7,9]|} a slice of an array literal.
  233.  
  234. \Xi{<pkg>|::|<var>} a variable from a package, e.g. |$pkg::var|, |@pkg::ary|.
  235.  
  236. \Xi{|\char`\\|<object>} reference to an object, e.g. |\$var|, |\%hash|.
  237.  
  238. \Xi{|*|<name>} refers to all objects represented by <name>.
  239. \\
  240. `|*n1|~|=|~|*n2|' makes |n1| an alias for |n2|.
  241. \\
  242. `|*n1|~|=|~|\$n2|' makes |$n1| an alias for |$n2|.
  243.  
  244. \end{enum}
  245.  
  246. You can always use a |{| <block> |}| returning the right type of reference
  247. instead of the variable identifier, e.g. |${|\ldots|}|, |&{|\ldots|}|.
  248. |$$p| is just a shorthand for |${$p}|.
  249.  
  250.  
  251. \section{Operators} 
  252.  
  253. \begin{tabbing}
  254. |    |\=|    |\= \kill
  255. |**| \> \> Exponentiation. \\
  256. |+ -| \> |* /| \> Addition, subtraction, multiplication, division. \\
  257. |%| \> \> Modulo division. \\
  258. \&| |\| \> \^ \> Bitwise AND, bitwise OR, bitwise exclusive OR. \\
  259. |>>| \> |<<| \> Bitwise shift right, bitwise shift left. \\
  260. \|\| \> \&\&   \> Logical OR, logical AND. \\
  261. |.| \> \> Concatenation of two strings. \\
  262. \kwd{x} \> \> Returns a string or array consisting of the left operand
  263. (an array or \\
  264. \> \> a string) repeated the number of times specified by the right operand.
  265. \end{tabbing}
  266.  
  267. All of the above operators have an associated assignment operator, e.g. `|.=|'.
  268.  
  269. \begin{tabbing}
  270. |    |\=|    |\= \kill
  271. |->| \> \> Dereference operator. \\
  272. |\| \> \> Reference (unary). \\
  273. |!| \> |~| \> Negation (unary), bitwise complement (unary). \\
  274. |++| \> |--| \> Auto-increment (magical on strings), auto-decrement. \\
  275. |=|\,|=| \> |!=| \> Numeric equality, inequality. \\
  276. \kwd{eq} \> \kwd{ne} \> String equality, inequality. \\
  277. |<|  \>  |>|  \> Numeric less than, greater than. \\
  278. \kwd{lt} \> \kwd{gt} \> String less than, greater than. \\
  279. |<=| \> |>=| \> Numeric less (greater) than or equal to. \\
  280. \kwd{le} \> \kwd{ge} \> String less (greater) than or equal. \\
  281. |<=>| \> \kwd{cmp} \> Numeric (string) compare. Returns -1, 0 or 1. \\
  282. |=~| \> |!~| \> Search pattern, substitution, or translation (negated). \\
  283. |..| \> \> Range (scalar context) or enumeration (array context). \\
  284. |? :|\>      \> Alternation (if-then-else) operator. \\
  285. |,| \> \> Comma operator, also list element separator.
  286. You can also use |=>|.\\
  287. \kwd{not} \> \> low-precedence negation. \\
  288. \kwd{and} \> \> low-precedence and. \\
  289. \kwd{or} \> \kwd{xor} \> low-precedence or, xor.
  290. \end{tabbing}
  291.  
  292. A `list' is a list of expressions, variables
  293. or lists. An array variable or an array slice may always be used
  294. instead of a list.  
  295. \\
  296. All Perl functions can be used as list operators, in which case they have 
  297. very high or very low precedence, depending on whether you look at the left
  298. side of the operator or at the right side of it.
  299. Only the operators \kwd{not}, \kwd{and}, \kwd{or} and \kwd{xor}, 
  300. have lower precedence.
  301. \newline Parentheses can be added around the parameter lists 
  302. to avoid precedence problems.
  303.  
  304.  
  305. \section{Statements} 
  306.  
  307. Every statement is an expression, optionally followed by a modifier,
  308. and terminated with a semicolon.  The semicolon may be omitted if the
  309. statement is the final one in a <block>.
  310.  
  311. Execution of expressions can depend on other expressions using one of
  312. the modifiers \kwd{if}, \kwd{unless}, \kwd{while} or \kwd{until},
  313. e.g.:
  314.  
  315. \quad    <expr1> \kwd{if} <expr2> |;| \\
  316. \quad    <expr1> \kwd{until} <expr2> |;|
  317.  
  318. Also, by using one of the logical operators \|\|, |&&| or |?:|, e.g.:
  319.  
  320. \quad    <expr1> \|\| <expr2> |;| \\
  321. \quad    <expr1> |?| <expr2> |:| <expr3> |;| 
  322.  
  323. Statements can be combined to form a <block> when enclosed in |{}|.
  324. <block>s may be used to control flow:
  325.  
  326. \quad    \kwd{if} |(|<expr>|)| <block> [ [ \kwd{elsif}
  327.     |(|<expr>|)| <BLOCK ...> ] \kwd{else}
  328.     <block> ]
  329. \\
  330. \quad    \kwd{unless} |(|<expr>|)| <block> [ \kwd{else}
  331.     <block> ]
  332. \\
  333. \quad    [ <label>\kwd{:} ] \kwd{while} |(|<expr>|)|
  334.     <block> [ \kwd{continue} <block> ]
  335. \\
  336. \quad    [ <label>\kwd{:} ] \kwd{until} |(|<expr>|)|
  337.     <block> [ \kwd{continue} <block> ]
  338. \\
  339. \quad    [ <label>\kwd{:} ] \kwd{for} |(| [ <expr> ] |;|
  340.     [ <expr> ] |;| [ <expr> ] |)| <block>
  341. \\
  342. \quad    [ <label>\kwd{:} ] \kwd{foreach} <var>\dag
  343.     |(|<array>|)| <block>
  344. \\
  345. \quad    [ <label>\kwd{:} ] <block> [ \kwd{continue} < block> ]
  346.  
  347. Program flow can be controlled with:
  348.  
  349. \begin{enum}{1cm}
  350.  
  351. \Xi{\kwd{goto} <label>}
  352. Continue execution at the specified label.
  353.  
  354. \Xi{\kwd{last} [ <label> ]}
  355. Immediately exits the loop in question. Skips continue block.
  356.  
  357. \Xi{\kwd{next} [ <label> ]}
  358. Starts the next iteration of the loop.
  359.  
  360. \Xi{\kwd{redo} [ <label> ]}
  361. Restarts the loop block without evaluating the conditional again.
  362.  
  363. \end{enum}
  364.  
  365. Special forms are:
  366.  
  367. \quad    \kwd{do} <block> \kwd{while} <expr> |;| \\
  368. \quad    \kwd{do} <block> \kwd{until} <expr> |;| \\
  369.  
  370. which are guaranteed to perform <block> once before testing <expr>, and
  371.  
  372. \quad    \kwd{do} <block>
  373.  
  374. which effectively turns <block> into an expression.
  375.  
  376.  
  377. \section{Subroutines, packages and modules} 
  378.  
  379. \begin{enum}{1cm}
  380.  
  381. \Xi{|\char`\&|<subroutine> <list>}
  382. Executes a <subroutine> declared by a \kwd{sub} declaration, and
  383. returns the value of the last expression evaluated in <subroutine> .
  384. \\
  385. <subroutine> can be an expression yielding a reference to a code object.
  386. \\
  387. The |&| may be omitted if the subroutine has been declared 
  388. before being used.
  389.  
  390. \Xi{\kwd{bless} <ref> [ \kwd{,} <package> ]}
  391. Turns the object <ref> into an object in <package>.
  392. Returns the reference.
  393.  
  394. \Xi{\kwd{caller} [ <expr> ]}
  395. Returns an array (\$package,\$file,\$line,...) for a specific subroutine
  396. call. `|caller|' returns this info for the current subroutine,
  397. `|caller(1)|' for the caller of this subroutine etc..  
  398. Returns \false{} if no caller.
  399.  
  400. \Xi{\kwd{do} <subroutine> <list>} 
  401. Deprecated form of |&|<subroutine> .
  402.  
  403. \Xi{\kwd{goto} |\char`\&|<subroutine>}
  404. Substitutes a call to <subroutine> for the current subroutine.
  405.  
  406. \Xi{\kwd{import} <module> [ <list> ]}
  407. Imports the named subroutines from <module>.
  408.  
  409. \Xi{\kwd{no} <module> [ <list> ]}
  410. Cancels imported semantics. See \kwd{use}.
  411.  
  412. \Xi{\kwd{package} <name>}
  413. Designates the remainder of the current block as a package.
  414.  
  415. \Xi{\kwd{require} \oEXPR}
  416. If <expr> is numeric, requires Perl to be at least that version.
  417. Otherwise <expr> must be the name of a file that is included from
  418. the Perl library. Does not include
  419. more than once, and yields a fatal error if the file does not evaluate
  420. to a \true{} value.
  421. \newline If <expr> is a bare word, assumes extension `|.pm|'
  422. for the name of the file.
  423.  
  424. \Xi{\kwd{return} <expr>}
  425. Returns from a subroutine with the value specified.
  426.  
  427. \Xi{\kwd{sub} <name> \{ <expr> |;| \ldots \}}
  428. Designates <name> as a subroutine. Parameters are passed by reference
  429. as array |@_|. Returns the value of the last expression evaluated. 
  430.  
  431. \Xi{[ \kwd{sub} ] |BEGIN| \{ <expr> |;| \ldots \}}
  432. Defines a setup <block> to be called before execution.
  433.  
  434. \Xi{[ \kwd{sub} ] |END| \{ <expr> |;| \dots \}}
  435. Defines a cleanup <block> to be called upon termination.
  436.  
  437. \Xi{\kwd{tie} <var>\kwd{,} <package>\kwd{,} [ <list> ]}
  438. Ties a variable to a package that will handle it.
  439. Can be used to bind a dbm or ndbm file to a hash. 
  440.  
  441. \Xi{\kwd{untie} <var>}
  442. Breaks the binding between the variable and the package.
  443.  
  444. \Xi{\kwd{use} <module> [ <list> ]}
  445. Imports semantics from the named module into the current package.
  446.  
  447. \end{enum}
  448.  
  449.  
  450. \section{Object oriented programming} 
  451.  
  452. Perl rules of object oriented programming:
  453.  
  454. \begin{enum}{3mm}
  455.  
  456. \Xj{$\bullet$}
  457. An object is simply a reference that happens to know which class it
  458. belongs to.
  459. \newline Objects are blessed, references are not.
  460.  
  461. \Xj{$\bullet$}
  462. A class is simply a package that happens to provide methods to deal
  463. with object references.
  464. \newline If a package fails to provide a method, the base classes as
  465. listed in |@ISA| are searched.
  466.  
  467. \Xj{$\bullet$}
  468. A method is simply a subroutine that expects an object reference (or a
  469. package name, for static methods) as the first argument.
  470. \newline Methods can be applied with:\\
  471. \hspace*{1cm}<method> <objref> <parameters>\quad\quad\quad\quad or\\
  472. \hspace*{1cm}<objref>|->|<method> <parameters>
  473.  
  474. \end{enum}
  475.  
  476.  
  477. \section{Arithmetic functions} 
  478.  
  479. \begin{enum}{1cm}
  480.  
  481. \Xi{\kwd{abs} \oEXPR}
  482. Returns the absolute value of its operand.
  483.  
  484. \Xi{\kwd{atan2} <y>\kwd{,} <x>}
  485. Returns the arctangent of <Y>/<X> in the range -$\pi$ to $\pi$.
  486.  
  487. \Xi{\kwd{cos} \oEXPR}
  488. Returns the cosine of <expr> (expressed in radians).
  489.  
  490. \Xi{\kwd{exp} \oEXPR}
  491. Returns |e| to the power of <expr>.
  492.  
  493. \Xi{\kwd{int} \oEXPR}
  494. Returns the integer portion of <expr>.
  495.  
  496. \Xi{\kwd{log} \oEXPR}
  497. Returns natural logarithm (base |e|) of <expr>.
  498.  
  499. \Xi{\kwd{rand} [ <expr> ]}
  500. Returns a random fractional number between 0 and the value of <expr>.
  501. If <expr> is omitted, returns a value between 0 and 1. 
  502.  
  503. \Xi{\kwd{sin} \oEXPR}
  504. Returns the sine of <expr> (expressed in radians).
  505.  
  506. \Xi{\kwd{sqrt} \oEXPR}
  507. Returns the square root of <expr>.
  508.  
  509. \Xi{\kwd{srand} [ <expr> ]}
  510. Sets the random number seed for the rand operator.
  511.  
  512. \Xi{\kwd{time}}
  513. Returns the number of seconds since January 1, 1970. Suitable for
  514. feeding to \kwd{gmtime} and \kwd{localtime}. 
  515.  
  516. \end{enum}
  517.  
  518.  
  519. \section{Conversion functions} 
  520.  
  521. \begin{enum}{1cm}
  522.  
  523. \Xi{\kwd{chr} \oEXPR}
  524. Returns the character represented by the decimal value <expr>.
  525.  
  526. \Xi{\kwd{gmtime} \oEXPR}
  527. Converts a time as returned by the \kwd{time} function to a 9-element
  528. array (0:\$sec, 1:\$min, 2:\$hour, 3:\$mday, 4:\$mon, 5:\$year, 6:\$wday,
  529. 7:\$yday, 8:\$isdst) with the time analyzed for the Greenwich time zone.
  530. \$mon has the range 0..11 and \$wday has the range 0..6.
  531.  
  532. \Xi{\kwd{hex} \oEXPR}
  533. Returns the decimal value of <expr> interpreted as an hex string.
  534.  
  535. \Xi{\kwd{localtime} \oEXPR}
  536. Converts a time as returned by the \kwd{time} function to {\it ctime\/}(3)
  537. string. In array context, returns a 9-element
  538. array with the time analyzed for the local time zone. 
  539.  
  540. \Xi{\kwd{oct} \oEXPR}
  541. Returns the decimal value of <expr> interpreted as an octal string. If
  542. <expr> starts off with |0x|, interprets it as a hex string instead.
  543.  
  544. \Xi{\kwd{ord} \oEXPR}
  545. Returns the ASCII value of the first character of <expr>.
  546.  
  547. \Xi{\kwd{vec} <expr>\kwd{,} <offset>\kwd{,} <bits>}
  548. Treats string <expr> as a vector of unsigned integers, and yields the bit at
  549. <offset>. <bits> must be between 1 and 32. May be assigned to.
  550.  
  551. \end{enum}
  552.  
  553. \newpage
  554.  
  555. \section{Structure conversion} 
  556.  
  557. \begin{enum}{1cm}
  558.  
  559. \Xi{\kwd{pack} <template>\kwd{,} <list>}
  560. Packs the values into a binary structure using <template>.
  561.  
  562. \Xi{\kwd{unpack} <template>\kwd{,} <expr>}
  563. Unpacks the structure <expr> into an array, using <template>.
  564.  
  565. <template> is a sequence of characters as follows:
  566.  
  567. \begin{tabbing}
  568. |  |\=|a |\=|/ |\=|A  |\= \kill
  569.   \> |a| \> / \> |A| \> ASCII string, null / space padded \\
  570.   \> |b| \> / \> |B| \> Bit string in ascending / descending order \\
  571.   \> |c| \> / \> |C| \> Native / unsigned char value \\
  572.   \> |f| \> / \> |d| \> Single / double float in native format \\
  573.   \> |h| \> / \> |H| \> Hex string, low / high nybble first. \\
  574.   \> |i| \> / \> |I| \> Signed / unsigned integer value \\
  575.   \> |l| \> / \> |L| \> Signed / unsigned long value \\
  576.   \> |n| \> / \> |N| \> Short / long in network (big endian) byte order \\
  577.   \> |s| \> / \> |S| \> Signed / unsigned short value \\
  578.   \> |u| \> / \> |p| \> Uuencoded string / Pointer to a string \\
  579.   \> |v| \> / \> |V| \> Short / long in VAX (little endian) byte order \\
  580.   \> |x| \> / \> |@| \> Null byte / null fill until position \\
  581.   \> |X| \>   \>     \> Backup a byte
  582. \end{tabbing}
  583.  
  584. Each character may be followed by a decimal number which will be used
  585. as a repeat count, `|*|' specifies all remaining arguments. \\
  586. If the format is preceded with |%|<n>, \kwd{unpack} returns an
  587. <n>-bit checksum instead. \\
  588. Spaces may be included in the template for readability purposes.
  589.  
  590. \end{enum}
  591.  
  592.  
  593. \section{String functions} 
  594.  
  595. \begin{enum}{1cm}
  596.  
  597. \Xi{\kwd{chomp} <list>\dag}
  598. Removes line endings from all elements of the list; 
  599. returns the (total) number of characters removed.
  600.  
  601. \Xi{\kwd{chop} <list>\dag}
  602. Chops off the last character on all elements of the list; returns the
  603. last chopped character. 
  604.  
  605. \Xi{\kwd{crypt} <plaintext>\kwd{,} <salt>}
  606. Encrypts a string.
  607.  
  608. \Xi{\kwd{eval} \oEXPR}
  609. <expr> is parsed and executed as if it were a Perl program. The value
  610. returned is the value of the last expression evaluated. If there is a
  611. syntax error or runtime error, an undefined string is returned by
  612. \kwd{eval}, and |$@| is set to the error message. 
  613. See also \kwd{eval} in section `Miscellaneous'.
  614.  
  615. \Xi{\kwd{index} <str>\kwd{,} <substr> [ \kwd{,} <offset> ]}
  616. Returns the position of <substr> in <str> at or after <offset>. If the
  617. substring is not found, returns |-1| (but see |$[| in section
  618. `Special variables').
  619.  
  620. \Xi{\kwd{length} \oEXPR}
  621. Returns the length in characters of the value of <expr>.
  622.  
  623. \Xi{\kwd{lc} <expr>}
  624. Returns a lower case version of <expr>.
  625.  
  626. \Xi{\kwd{lcfirst} <expr>}
  627. Returns <expr> with the first character in lower case.
  628.  
  629. \Xi{\kwd{quotemeta} <expr>}
  630. Returns <expr> with all regexp meta-characters quoted.
  631.  
  632. \Xi{\kwd{rindex} <str>\kwd{,} <substr> [ \kwd{,} <offset> ]}
  633. Returns the position of the last <substr> in <str> at or
  634. before <offset>.
  635.  
  636. \Xi{\kwd{substr} <expr>\kwd{,} <offset> [ \kwd{,} <len> ]}
  637. Extracts a substring out of <expr> and returns it. If <offset>
  638. is negative, counts from the end of the string. 
  639. May be assigned to.
  640.  
  641. \Xi{\kwd{uc} <expr>}
  642. Returns an upper case version of <expr>.
  643.  
  644. \Xi{\kwd{ucfirst} <expr>}
  645. Returns <expr> with the first character in upper case.
  646.  
  647. \end{enum}
  648.  
  649.  
  650. \section{Array and list functions} 
  651.  
  652. \begin{enum}{1cm}
  653.  
  654. \Xi{\kwd{delete} \$<hash>\{<key>\}}
  655. Deletes the specified value from the specified hash.
  656. Returns the deleted value unless <hash> is \kwd{tie}d to a package that
  657. does not support it.
  658.  
  659. \Xi{\kwd{each} |\%|<hash>}
  660. Returns a 2-element array consisting of the key and value for the next
  661. value of the hash. Entries are returned in an apparently
  662. random order. After all values of the hash have been returned, a null array is
  663. returned. The next call to \kwd{each} after that will start iterating again.
  664.  
  665. \Xi{\kwd{exists} \oEXPR}
  666. Checks if the specified hash key exists in its hash array.
  667.  
  668. \Xi{\vbox{\vspace*{3pt}
  669.           \hbox{\kwd{grep} <expr>\kwd{,} <list>}
  670.           \hbox{\kwd{grep} <block> <list>}}}
  671. Evaluates <expr> or <block> for each element of the <list>, 
  672. locally setting |$_|
  673. to refer to the element. Modifying |$_| will modify the corresponding
  674. element from <list>. Returns the array of elements from <list> for which
  675. <expr> returned \true. 
  676.  
  677. \Xi{\kwd{join} <expr>\kwd{,} <list>}
  678. Joins the separate strings of <list> into a single string with fields
  679. separated by the value of <expr>, and returns the string.
  680.  
  681. \Xi{\kwd{keys} |\%|<hash>}
  682. Returns an array of all the keys of the named hash.
  683.  
  684. \Xi{\vbox{\vspace*{3pt}
  685.           \hbox{\kwd{map} <expr>\kwd{,} <list>}
  686.           \hbox{\kwd{map} <block> <list>}}}
  687. Evaluates <expr> or <block> for each element of the <list>, 
  688. locally setting |$_|
  689. to refer to the element. Modifying |$_| will modify the corresponding
  690. element from <list>. Returns the list of results.
  691.  
  692. \Xi{\kwd{pop} |@|<array>}
  693. Pops off and returns the last value of the array.
  694.  
  695. \Xi{\kwd{push} |@|<array>\kwd{,} <list>}
  696. Pushes the values of <list> onto the end of <array>.
  697.  
  698. \Xi{\kwd{reverse} <list>}
  699. In array context: returns the <list> in reverse order. \\
  700. In scalar
  701. context: returns the first element of <list> with bytes reversed. 
  702.  
  703. \Xi{\kwd{scalar} |@|<array>}
  704. Returns the number of elements in the array.
  705.  
  706. \Xi{\kwd{scalar} |\%|<hash>}
  707. Returns a \true{} value if the hash has elements defined.
  708.  
  709. \Xi{\kwd{shift} [ |@|<array> ]}
  710. Shifts the first value of the array off and returns it, shortening the
  711. array by 1 and moving everything down. If |@|<array> is omitted, shifts
  712. |@ARGV| in main and |@_| in subroutines.  
  713.  
  714. \Xi{\kwd{sort}  [ <subroutine> ] <list>}
  715. Sorts the <list> and returns the sorted array value. If <subroutine>
  716. is specified, gives the name of a subroutine that returns less than
  717. zero, zero, or greater than zero, depending on how the elements of the
  718. array, available to the routine as |$a| and |$b|, are to be ordered.
  719. \\
  720. <subroutine> may be the name of a user-defined routine, or a <block>.
  721.  
  722. \Xi{\kwd{splice} |@|<array>\kwd{,} <offset> [ \kwd{,} <length> [ \kwd{,} <list> ] ]}
  723. Removes the elements of |@|<array> designated by <offset> and
  724. <length>, and replaces them with <list> (if specified). \\
  725. Returns the elements removed.
  726.  
  727. \Xi{\kwd{split} [ <pattern> [ \kwd{,} \oEXPR{} [ \kwd{,} <limit> ] ] ]}
  728. Splits a string into an array of strings, and returns it. If <limit>
  729. is specified, splits into at most that number of fields. If <pattern> is
  730. also omitted, splits on whitespace. If
  731. not in array context: returns number of fields and splits to |@_|.
  732. See also: `Search and replace functions'.
  733.  
  734. \Xi{\kwd{unshift} |@|<array>\kwd{,} <list>}
  735. Prepends list to the front of the array, and returns the number of
  736. elements in the new array.
  737.  
  738. \Xi{\kwd{values} |\%|<hash>}
  739. Returns a normal array consisting of all the values of the named
  740. hash. 
  741.  
  742. \end{enum}
  743.  
  744.  
  745.  
  746. \newpage
  747.  
  748. \section{Regular expressions} 
  749. \def\xtraspace{\vspace{5pt}}
  750.  
  751. Each character matches itself, unless it is one of the special
  752. characters |+?.*^$()[]{}|\||\|.
  753. The special meaning of these characters can be escaped using a `|\|'.
  754.  
  755. \begin{enum}{1cm}
  756.  
  757. \Xj{|.|}
  758. matches an arbitrary character, but not a newline unless it is a
  759. single-line match (see \kwd{m}|//|\kwd{s}).
  760.  
  761. \Xj{|(|\ldots|)|}
  762. groups a series of pattern elements to a single element.
  763.  
  764. \Xj{\^}
  765. matches the beginning of the target. In multi-line mode (see
  766. \kwd{m}|//|\kwd{m}) also matches after every newline character.
  767.  
  768. \Xj{\$}
  769. matches the end of the line.
  770. In multi-line mode also matches before every newline character.
  771.  
  772. \Xj{|\char`\[|\ldots|\char`\]|}
  773. denotes a class of characters to match. |[|\^\ldots|]| negates the class.
  774.  
  775. \Xj{|(|\ldots\|\ldots\|\ldots|)|}
  776. matches one of the alternatives.
  777.  
  778. \Xj{|(?|\char`\# ~<text> |)|}
  779. Comment.
  780.  
  781. \Xj{|(?:| <regexp> |)|}
  782. Like |(|<regexp>|)| but does not make back-references.
  783.  
  784. \Xj{|(?=| <regexp> |)|}
  785. Zero width positive look-ahead assertion.
  786.  
  787. \Xj{|(?!| <regexp> |)|}
  788. Zero width negative look-ahead assertion.
  789.  
  790. \Xj{|(?| <modifier> |)|}
  791. Embedded pattern-match modifier. <modifier> can be one or more of
  792. \kwd{i}, \kwd{m}, \kwd{s} or \kwd{x}.
  793.  
  794. \end{enum}
  795.  
  796. \xtraspace
  797. Quantified subpatterns match as many times as possible. 
  798. When followed with a `|?|' they match the minimum number of times.
  799. These are the quantifiers:
  800.  
  801. \begin{enum}{1cm}
  802.  
  803. \Xj{|+|}
  804. matches the preceding pattern element one or more times.
  805.  
  806. \Xj{|?|}
  807. matches zero or one times.
  808.  
  809. \Xj{|*|}
  810. matches zero or more times.
  811.  
  812. \Xj{\{<n>|,|<m>\}}
  813. denotes the minimum <n> and maximum <m> match count. |{|<n>|}| means
  814. exactly <n> times; |{|<n>|,}| means at least <n> times. 
  815.  
  816. \end{enum}
  817.  
  818. \xtraspace
  819. A `|\|' escapes any special meaning of the following character
  820. if non-alphanumeric, but it turns most alphanumeric characters
  821. into something special:
  822.  
  823. \begin{enum}{1cm}
  824.  
  825. \Xj{|\char`\\w|}
  826. matches alphanumeric, including `|_|', |\W| matches non-alphanumeric.
  827.  
  828. \Xj{|\char`\\s|}
  829. matches whitespace, |\S| matches non-whitespace.
  830.  
  831. \Xj{|\char`\\d|}
  832. matches numeric, |\D| matches non-numeric.
  833.  
  834. \Xj{|\char`\\A|}
  835. matches the beginning of the string, |\Z| matches the end.
  836.  
  837. \Xj{|\char`\\b|}
  838. matches word boundaries, |\B| matches non-boundaries.
  839.  
  840. \Xj{|\char`\\G|}
  841. matches where the previous \kwd{m}|//|\kwd{g} search left off.
  842.  
  843. \Xj{|\char`\\n|, |\char`\\r|, |\char`\\f|, |\char`\\t| etc.} 
  844. have their usual meaning.
  845.  
  846. \Xj{|\char`\\w|, |\char`\\s| and |\char`\\d|}
  847.  may be used within character classes, |\b| denotes backspace in this context.
  848.  
  849. \end{enum}
  850.  
  851. \xtraspace
  852. Back-references:
  853.  
  854. \begin{enum}{1cm}
  855.  
  856. \Xj{|\char`\\1|\ldots|\char`\\9|} 
  857. refer to matched sub-expressions, grouped with |()|, inside the match. 
  858.  
  859. \Xj{|\char`\\10|}
  860. and up can also be used if the pattern
  861. matches that many sub-expressions. 
  862.  
  863. \end{enum}
  864.  
  865. See also |$1|\ldots|$9|, |$+|, |$&|, |$`| and |$'| in section `Special
  866. variables'.
  867.  
  868. \xtraspace
  869. With modifier \kwd{x}, whitespace can be used in the patterns for
  870. readability purposes.
  871.  
  872. \newpage
  873.  
  874. \section{Search and replace functions}
  875.  
  876. \begin{enum}{1cm}
  877.  
  878. \catcode`\~=\other
  879.  
  880. \Xi{[ <expr> |=~| ] [ \kwd{m} ] |/|<pattern>|/| [ \kwd{g} ] [ \kwd{i} ] [ \kwd{m} ] [ \kwd{o} ] [ \kwd{s} ] [ \kwd{x} ]}
  881. Searches <expr> (default: |$_|) for a pattern. If you prepend an
  882. \kwd{m} you can use almost any pair of delimiters instead of the slashes. If
  883. used in array context, an array is returned consisting of the
  884. sub-expressions matched by the parentheses in pattern, i.e.
  885. |($1,$2,$3,|\ldots|)|.
  886. \\
  887. Optional modifiers:
  888. \kwd{g} matches as many times as possible; 
  889. \kwd{i} searches in a case-insensitive manner; 
  890. \kwd{o} interpolates variables only once.
  891. \newline 
  892. \kwd{m} treats the string as multiple lines; 
  893. \kwd{s} treats the string as a single line; 
  894. \kwd{x} allows for regular expression extensions.
  895. \\
  896. If <pattern> is empty, the most recent pattern from a
  897. previous match or replacement is used.
  898. \\
  899. With \kwd{g} the match can be used as an iterator in scalar context.
  900.  
  901. \Xi{|?|<pattern>|?|}
  902. This is just like the |/|<pattern>|/| search, except that it matches
  903. only once between calls to the \kwd{reset} operator.
  904.  
  905. \Xi{[ |\$|<var> |=~| ] \kwd{s}|/|<pattern>|/|<replacement>|/| [ \kwd{e} ] [ \kwd{g} ] [ \kwd{i} ] [ \kwd{m} ] [ \kwd{o} ] [ \kwd{s} ] [ \kwd{x} ]}
  906. Searches a string for a pattern, and if found, replaces that pattern
  907. with the replacement text. It returns the number of substitutions
  908. made, if any, otherwise it returns \false{}. 
  909. \\
  910. Optional modifiers: \kwd{g} replaces all occurrences of the pattern;
  911. \kwd{e} evaluates the replacement string as a Perl expression; for the other 
  912. modifiers, see |/|<pattern>|/| matching. Almost any delimiter may
  913. replace the slashes; if single quotes are used, no interpolation is
  914. done on the strings between the delimiters, otherwise they are interpolated
  915. as if inside double quotes.
  916. \\
  917. If bracketing delimiters are used, <pattern> and <replacement> 
  918. may have their own delimiters, e.g. |s(foo)[bar]|.
  919. \\
  920. If <pattern> is empty, the most recent pattern from a previous match or replacement is used.
  921.  
  922. \Xi{[ |\$|<var> |=~| ] \kwd{tr}|/|<searchlist>|/|<replacementlist>|/| [ \kwd{c} ] [ \kwd{d} ] [ \kwd{s} ]}
  923. Translates all occurrences of the characters found in the search list
  924. with the corresponding character in the replacement list. It returns
  925. the number of characters replaced. \kwd{y} may be used instead of \kwd{tr}. 
  926. \\
  927. Optional modifiers: \kwd{c} complements the <searchlist>; \kwd{d}
  928. deletes all characters found in <searchlist> that do not have a
  929. corresponding character in <replacementlist>; \kwd{s} squeezes all
  930. sequences of characters that are translated into the same target
  931. character into one occurrence of this character.
  932.  
  933. \Xi{\kwd{pos} <scalar>}
  934. Returns the position where the last \kwd{m}|//|\kwd{g} search left off
  935. for <scalar>. May be assigned to.
  936.  
  937. \Xi{\kwd{study} [ |\$|<var>\dag{} ]}
  938. Studies the scalar variable |$|<var> in anticipation of performing many
  939. pattern matches on its contents before the variable is next modified.
  940.  
  941. \end{enum}
  942.  
  943. \newpage
  944.  
  945. \section{File test operators} 
  946.  
  947. These unary operators take one argument, either a filename or a
  948. filehandle, and test the associated file to see if something is true
  949. about it. If the argument is omitted, they test |$_| (except for |-t,|
  950. which tests |STDIN|). If the special argument |_| (underscore) is
  951. passed, they use the info of the preceding test or \kwd{stat} call.
  952.  
  953. \begin{enum}{2.5cm}
  954.  
  955. \Xi{|-r -w -x|}  File is readable/writable/executable by effective uid/gid.
  956.  
  957. \Xi{|-R -W -X|}  File is readable/writable/executable by real uid/gid.
  958.  
  959. \Xi{|-o  -O|}  File is owned by effective/real uid. 
  960.  
  961. \Xi{|-e  -z|}  File exists, has zero size. 
  962.  
  963. \Xi{|-s|}  File exists and has non-zero size. Returns the size.
  964.  
  965. \Xi{|-f  -d|}  File is a plain file, a directory.
  966.  
  967. \Xi{|-l  -S  -p|}  File is a symbolic link, a socket, a named pipe (FIFO). 
  968.  
  969. \Xi{|-b  -c|}  File is a block/character special file. 
  970.  
  971. \Xi{|-u  -g  -k|}  File has setuid/setgid/sticky bit set. 
  972.  
  973. \Xi{|-t|}  Tests if filehandle (|STDIN| by default) is opened to a tty.
  974.  
  975. \Xi{|-T  -B|}  File is a text/non-text (binary) file.  |-T| and |-B|
  976. return \true{} on a null file, or a file at EOF when testing a filehandle. 
  977.  
  978. \Xi{|-M  -A  -C|}  File modification/access/inode change time. Measured
  979. in days. Value returned reflects the file age at the time the script
  980. started. See also |$^T| in section `Special variables'.
  981.  
  982. \end{enum}
  983.  
  984.  
  985. \section{File operations} 
  986.  
  987. Functions operating on a list of files return the number of files
  988. successfully operated upon.
  989.  
  990. \begin{enum}{1cm}
  991.  
  992. \Xi{\kwd{chmod} <list>}
  993. Changes the permissions of a list of files. The first element of the
  994. list must be the numerical mode. 
  995.  
  996. \Xi{\kwd{chown} <list>}
  997. Changes the owner and group of a list of files. The first two elements
  998. of the list must be the numerical uid and gid. 
  999.  
  1000. \Xi{\kwd{truncate} <file>\kwd{,} <size>}
  1001. truncates <file> to <size>. <file> may be a filename or a filehandle.
  1002.  
  1003. \Xi{\kwd{link} <oldfile>\kwd{,} <newfile>}
  1004. Creates a new filename linked to the old filename.
  1005.  
  1006. \Xi{\kwd{lstat} <file>}
  1007. Like stat, but does not traverse a final symbolic link.
  1008.  
  1009. \Xi{\kwd{mkdir} <dir>\kwd{,} <mode>}
  1010. Creates a directory with given permissions. Sets |$!| on failure.
  1011.  
  1012. \Xi{\kwd{readlink} \oEXPR}
  1013. Returns the value of a symbolic link.
  1014.  
  1015. \Xi{\kwd{rename} <oldname>\kwd{,} <newname>}
  1016. Changes the name of a file.
  1017.  
  1018. \Xi{\kwd{rmdir} <filename>\dag}
  1019. Deletes the directory if it is empty. Sets |$!| on failure.
  1020.  
  1021. \pagebreak[2]
  1022. \Xi{\kwd{stat} <file>}
  1023. Returns a 13-element array (0:\$dev, 1:\$ino, 2:\$mode, 3:\$nlink,
  1024. 4:\$uid, 5:\$gid, 6:\$rdev, 7:\$size, 8:\$atime, 9:\$mtime,
  1025. 10:\$ctime, 11:\$blksize, 12:\$blocks). <file> can be a filehandle, an
  1026. expression evaluating to a filename, or |_| to refer to the last file
  1027. test operation or \kwd{stat} call.
  1028. \\
  1029. Returns a null list if the \kwd{stat} fails.
  1030.  
  1031. \Xi{\kwd{symlink} <oldfile>\kwd{,} <newfile>}
  1032. Creates a new filename symbolically linked to the old filename.
  1033.  
  1034. \Xi{\kwd{unlink} <list>}
  1035. Deletes a list of files.
  1036.  
  1037. \Xi{\kwd{utime} <list>}
  1038. Changes the access and modification times. The first two elements of
  1039. the list must be the numerical access and modification times.
  1040.  
  1041. \end{enum}
  1042.  
  1043.  
  1044.  
  1045.  
  1046. \section{Input / Output} 
  1047.  
  1048. In input/output operations, <filehandle> may be a filehandle as opened
  1049. by the \kwd{open} operator, a pre-defined filehandle (e.g. |STDOUT|)
  1050. or a scalar variable which evaluates to the name of a filehandle to be
  1051. used.
  1052.  
  1053. \begin{enum}{1cm}
  1054.  
  1055. \Xi{\<<filehandle>\>}
  1056. In scalar context: reads a single line from the file opened on <filehandle>. 
  1057. In array context: reads the whole file.
  1058.  
  1059. \Xi{\<\,\>}
  1060. Reads from the input stream formed by the files specified in
  1061. |@ARGV|, or standard input if no arguments were supplied.
  1062.  
  1063. \Xi{\kwd{binmode} <filehandle>}
  1064. Arranges for the file opened on <filehandle> to be read or written in
  1065. \textit{binary} mode as opposed to \textit{text} mode (null-operation on UNIX).
  1066.  
  1067. \Xi{\kwd{close} <filehandle>}
  1068. Closes the file or pipe associated with the file handle.
  1069.  
  1070. \Xi{\kwd{dbmclose} |\%|<hash>}
  1071. Deprecated, use \kwd{untie} instead.
  1072.  
  1073. \Xi{\kwd{dbmopen} |\%|<hash>\kwd{,} <dbmname>\kwd{,} <mode>}
  1074. Deprecated, use \kwd{tie} instead.
  1075.  
  1076. \Xi{\kwd{eof} <filehandle>}
  1077. Returns 1 if the next read will return end of file, or if the file is
  1078. not open. 
  1079.  
  1080. \Xi{\kwd{eof}}
  1081. Returns the eof status for the last file read.
  1082.  
  1083. \Xj{\kwd{eof(}\,\kwd{)}}
  1084. Indicates eof on the pseudo-file formed of the files listed on the
  1085. command line. 
  1086.  
  1087. \Xi{\kwd{fcntl} <filehandle>\kwd{,} <function>\kwd{,} |\$|<var>}
  1088. Implements the {\it fcntl\/}(2) function. This function has non-standard
  1089. return values. See the manual for details. 
  1090.  
  1091. \Xi{\kwd{fileno} <filehandle>}
  1092. Returns the file descriptor for a given (open) file.
  1093.  
  1094. \Xi{\kwd{flock} <filehandle>\kwd{,} <operation>}
  1095. Calls {\it flock\/}(2) on the file. <operation> formed by adding 1 (shared), 2
  1096. (exclusive), 4 (non-blocking) or 8 (unlock). 
  1097.  
  1098.  
  1099. \Xi{\kwd{getc} [ <filehandle> ]}
  1100. Yields the next character from the file, or |""| on end of file.
  1101. \newline If <filehandle> is omitted, reads from |STDIN|. 
  1102.  
  1103. \Xi{\kwd{ioctl} <filehandle>\kwd{,} <function>\kwd{,} |\$|<var>}
  1104. performs {\it ioctl}(2) on the file. This function has non-standard
  1105. return values. See the manual for details. 
  1106.  
  1107. \Xi{\kwd{open} <filehandle> [ \kwd{,} <filename> ]}
  1108. Opens a file and associates it with <filehandle>. If <filename> is
  1109. omitted, the scalar variable of the same name as the <filehandle> must
  1110. contain the filename.
  1111.  
  1112. The following filename conventions apply when opening a file.
  1113.  
  1114. \begin{enum}{2cm}
  1115. \Xi{|"|<file>|"|} open <file> for input. Also |"<|<file>|"|.
  1116.  
  1117. \Xi{|">|<file>|"|} open <file> for output, creating it if necessary.
  1118.  
  1119. \Xi{|">>|<file>|"|} open <file> in append mode.
  1120.  
  1121. \Xi{|"+\<|<file>|"|} open <file> with read/write access.
  1122.  
  1123. \Xi{|"\||<cmd>|"|} opens a pipe to command <cmd>. If <cmd> is `|-|', forks.
  1124.  
  1125. \Xi{|"|<cmd>|\|"|} opens a pipe from command <cmd>. If <cmd> is `|-|', forks.
  1126. \end{enum}
  1127.  
  1128. <file> may be |&|<filehnd>, in which case the new file handle is
  1129. connected to the (previously opened) filehandle <filehnd>.
  1130. If it is |&=|<n>, <file> will be connected to the given file descriptor.
  1131.  
  1132. \kwd{open} 
  1133. returns \kwd{undef} upon failure, \true{} otherwise.
  1134.  
  1135. \Xi{\kwd{pipe} <readhandle>\kwd{,} <writehandle>}
  1136. Returns a pair of connected pipes.
  1137.  
  1138. \Xi{\kwd{print} [ <filehandle> ] [ <list>\dag ]}
  1139. Prints the elements of LIST, converting them to strings if needed. If
  1140. <filehandle> is omitted, prints by default to standard output (or to
  1141. the last selected output channel, see \kwd{select}).
  1142.  
  1143. \Xi{\kwd{printf} [ <filehandle> ] <list> ]}
  1144. Equivalent to |print| <filehandle> |sprintf| <list>.
  1145.  
  1146. \Xi{\kwd{read} <filehandle>\kwd{,} |\$|<var>\kwd{,} <length> [ \kwd{,} <offset> ]}
  1147. Reads <length> binary bytes from the file into the variable at
  1148. <offset>. Returns number of bytes actually read. 
  1149.  
  1150. \Xi{\kwd{seek} <filehandle>\kwd{,} <position>\kwd{,} <whence>}
  1151. Arbitrarily positions the file. Returns 1 upon success, 0 otherwise.
  1152.  
  1153. \Xi{\kwd{select} [ <filehandle> ]}
  1154. Returns the currently selected filehandle. 
  1155. Sets the current default filehandle for output operations if
  1156. <filehandle> is supplied.
  1157.  
  1158. \Xi{\kwd{select} <rbits>\kwd{,} <wbits>\kwd{,} <nbits>\kwd{,} <timeout>}
  1159. Performs a {\it select\/}(2) system call with the same parameters.
  1160.  
  1161. \Xi{\kwd{sprintf} <format>\kwd{,} <list>}
  1162. Returns a string formatted by (almost all of) the usual {\it printf}(3)
  1163. conventions. 
  1164.  
  1165. \Xi{\kwd{sysread} <filehandle>\kwd{,} |\$|<var>\kwd{,} <length> [ \kwd{,} <offset> ]}
  1166. Reads <length> bytes into |$|<var> at <offset>.
  1167.  
  1168. \Xi{\kwd{syswrite} <filehandle>\kwd{,} <scalar>\kwd{,} <length> [ \kwd{,} <offset> ]}
  1169. Writes <length> bytes from <scalar> at <offset>.
  1170.  
  1171. \Xi{\kwd{tell} [ <filehandle> ]}
  1172. Returns the current file position for the file. If <filehandle> is
  1173. omitted, assumes the file last read. 
  1174.  
  1175. \end{enum}
  1176.  
  1177.  
  1178. \section{Formats} 
  1179.  
  1180. \begin{enum}{1cm}
  1181.  
  1182. \Xi{\kwd{formline} <picture>\kwd{,} <list>}
  1183. Formats <list> according to <picture> and accumulates the result into \$\^|A|.
  1184.  
  1185. \Xi{\kwd{write} [ <filehandle> ]}
  1186. Writes a formatted record to the specified file, using the format
  1187. associated with that file.
  1188.  
  1189. \end{enum}
  1190.  
  1191. Formats are defined as follows:
  1192.  
  1193. \kwd{format} [ <name> ] |=| \\
  1194. <formlist> \\
  1195. |.|
  1196.  
  1197. <formlist> pictures the lines, and contains the arguments which will
  1198. give values to the fields in the lines. <name> defaults to |STDOUT| if
  1199. omitted.\\
  1200. Picture fields are:
  1201.  
  1202. \begin{tabbing}
  1203. |  |\=|         |\=\kill
  1204. \>|@<<<|\ldots    \> left adjusted field, repeat the |<| to denote the desired
  1205.                      width; \\
  1206. \>|@>>>|\ldots    \> right adjusted field; \\
  1207. \>|@|\|\|\|\ldots \> centered field; \\
  1208. \>|@#.##|\ldots   \> numeric format with implied decimal point; \\
  1209. \>|@*|            \> a multi-line field.
  1210. \end{tabbing}
  1211.  
  1212. Use \^ instead of |@| for multi-line block filling.
  1213.  
  1214. Use |~| at the beginning of a line to suppress unwanted empty lines.
  1215.  
  1216. Use |~~| at the beginning of a line to have this format line repeated
  1217. until all fields are exhausted. 
  1218.  
  1219. Set |$-| to zero to force a page break.
  1220.  
  1221. See also |$|\^, |$~|, |$^A|, |$^F|, |$-| and |$=| 
  1222. in section `Special variables'.
  1223.  
  1224.  
  1225. \section{Directory reading routines} 
  1226.  
  1227. \begin{enum}{1cm}
  1228.  
  1229. \Xi{\kwd{closedir} <dirhandle>}
  1230. Closes a directory opened by opendir.
  1231.  
  1232. \Xi{\kwd{opendir} <dirhandle>\kwd{,} <dirname>}
  1233. Opens a directory on the handle specified.
  1234.  
  1235. \Xi{\kwd{readdir} <dirhandle>}
  1236. Returns the next entry (or an array of entries) in the directory.
  1237.  
  1238. \Xi{\kwd{rewinddir} <dirhandle>}
  1239. Positions the directory to the beginning.
  1240.  
  1241. \Xi{\kwd{seekdir} <dirhandle>\kwd{,} <pos>}
  1242. Sets position for readdir on the directory.
  1243.  
  1244. \Xi{\kwd{telldir} <dirhandle>}
  1245. Returns the postion in the directory.
  1246.  
  1247. \end{enum}
  1248.  
  1249.  
  1250. \section{System interaction} 
  1251.  
  1252. \begin{enum}{1cm}
  1253.  
  1254. \Xi{\kwd{alarm} <expr>}
  1255. Schedules a |SIGALRM| to be delivered after <expr> seconds. 
  1256.  
  1257. \Xi{\kwd{chdir} [ <expr> ]}
  1258. Changes the working directory.
  1259. \newline Uses |$ENV{"HOME"}| or |$ENV{"LOGNAME"}| if <expr> is omitted.
  1260.  
  1261. \Xi{\kwd{chroot} <filename>\dag}
  1262. Changes the root directory for the process and its children.
  1263.  
  1264. \Xi{\kwd{die} [ <list> ]}
  1265. Prints the value of <list> to |STDERR| and exits with the current
  1266. value of |$!| (errno). If |$!| is 0, exits with the value of |($? >> 8)|.
  1267. If |($? >> 8)| is 0, exits with 255. <list> defaults to
  1268. |"Died"|.
  1269.  
  1270. \Xi{\kwd{exec} <list>}
  1271. Executes the system command in <list>; does not return.
  1272.  
  1273. \Xi{\kwd{exit} [ <expr> ]}
  1274. Exits immediately with the value of |EXPR|, which defaults to |0| (zero).
  1275. Calls |END| routines and object destructors before exiting.
  1276.  
  1277. \Xi{\kwd{fork}}
  1278. Does a {\it fork\/}(2) system call. Returns the child pid to the parent
  1279. process and zero to the child process. 
  1280.  
  1281. \Xi{\kwd{getlogin}}
  1282. Returns the current login name as known by the system.
  1283.  
  1284. \Xi{\kwd{getpgrp} [ <pid> ]}
  1285. Returns the process group for process <pid> (0, or omitted,  means the
  1286. current process). 
  1287.  
  1288. \Xi{\kwd{getppid}}
  1289. Returns the process id of the parent process.
  1290.  
  1291. \Xi{\kwd{getpriority} <which>\kwd{,} <who>}
  1292. Returns the current priority for a process, process group, or user.
  1293.  
  1294. \Xi{\kwd{glob} <pat>}
  1295. Returns a list of filenames that match the shell pattern <pat>.
  1296.  
  1297. \Xi{\kwd{kill} <list>}
  1298. Sends a signal to a list of processes. The first element of the list
  1299. must be the signal to send (numeric, or its name as a string). 
  1300.  
  1301. \Xi{\kwd{setpgrp} <pid>\kwd{,} <pgrp>}
  1302. Sets the process group for the <pid> (0 = current process).
  1303.  
  1304. \Xi{\kwd{setpriority} <which>\kwd{,} <who>\kwd{,} <prio>}
  1305. Sets the current priority for a process, process group, or a user.
  1306.  
  1307. \Xi{\kwd{sleep} [ <expr> ]}
  1308. Causes the script to sleep for <expr> seconds, or forever if no
  1309. <expr>. Returns the number of seconds actually slept. 
  1310.  
  1311. \Xi{\kwd{syscall} <list>}
  1312. Calls the system call specified in the first element of the list,
  1313. passing the rest of the list as arguments to the call. 
  1314.  
  1315. \Xi{\kwd{system} <list>}
  1316. Does exactly the same thing as \kwd{exec }<list> except that a fork is
  1317. performed first, and the parent process waits for the child process to complete. 
  1318.  
  1319. \Xi{\kwd{times}}
  1320. Returns a 4-element array (0:\$user, 1:\$system, 2:\$cuser,
  1321. 3:\$csystem) giving the user and system times, in seconds, for this
  1322. process and the children of this process.
  1323.  
  1324. \Xi{\kwd{umask} [ <expr> ]}
  1325. Sets the umask for the process and returns the old one. If <expr> is
  1326. omitted, returns current umask value. 
  1327.  
  1328. \Xi{\kwd{wait}}
  1329. Waits for a child process to terminate and returns the pid of the
  1330. deceased process (-1 if none). The status is returned in |$?|. 
  1331.  
  1332. \Xi{\kwd{waitpid} <pid>\kwd{,} <flags>}
  1333. Performs the same function as the corresponding system call.
  1334.  
  1335. \Xi{\kwd{warn} [ <list> ]}
  1336. Prints the message on |STDERR| like \kwd{die}, but does not exit.
  1337. \newline <list> defaults to |"Warning: something's wrong"|.
  1338.  
  1339. \end{enum}
  1340.  
  1341.  
  1342. \section{Networking} 
  1343.  
  1344. \begin{enum}{1cm}
  1345.  
  1346. \Xi{\kwd{accept} <newsocket>\kwd{,} <genericsocket>}
  1347. Accepts a new socket.
  1348.  
  1349. \Xi{\kwd{bind} <socket>\kwd{,} <name>}
  1350. Binds the <name> to the <socket>.
  1351.  
  1352. \Xi{\kwd{connect} <socket>\kwd{,} <name>}
  1353. Connects the <name> to the <socket>.
  1354.  
  1355. \Xi{\kwd{getpeername} <socket>}
  1356. Returns the socket address of the other end of the <socket>.
  1357.  
  1358. \Xi{\kwd{getsockname} <socket>}
  1359. Returns the name of the socket.
  1360.  
  1361. \Xi{\kwd{getsockopt} <socket>\kwd{,} <level>\kwd{,} <optname>}
  1362. Returns the socket options.
  1363.  
  1364. \Xi{\kwd{listen} <socket>\kwd{,} <queuesize>}
  1365. Starts listening on the specified <socket>.
  1366.  
  1367. \Xi{\kwd{recv} <socket>\kwd{,} <scalar>\kwd{,} <length>\kwd{,} <flags>}
  1368. Receives a message on <socket>.
  1369.  
  1370. \Xi{\kwd{send} <socket>\kwd{,} <msg>\kwd{,} <FLAGS [ >\kwd{,} <to> ]}
  1371. Sends a message on the <socket>.
  1372.  
  1373. \Xi{\kwd{setsockopt} <socket>\kwd{,} <level>\kwd{,} <optname>\kwd{,} <optval>}
  1374. Sets the requested socket option.
  1375.  
  1376. \Xi{\kwd{shutdown} <socket>\kwd{,} <how>}
  1377. Shuts down a <socket>.
  1378.  
  1379. \Xi{\kwd{socket} <socket>\kwd{,} <domain>\kwd{,} <type>\kwd{,} <protocol>}
  1380. Creates a <socket> in <domain> with <type> and <protocol>.
  1381.  
  1382. \Xi{\kwd{socketpair} <socket1>\kwd{,} <socket2>\kwd{,} <domain>\kwd{,} <type>\kwd{,} <protocol>}
  1383. As socket, but creates a pair of bi-directional sockets.
  1384.  
  1385. \end{enum}
  1386.  
  1387.  
  1388. \section{SystemV IPC} 
  1389.  
  1390. \begin{enum}{1cm}
  1391.  
  1392. \Xi{\kwd{msgctl} <id>\kwd{,} <cmd>\kwd{,} <args>}
  1393. Calls {\it msgctl\/}(2). If <cmd> is |&IPC_STAT| then <arg> must 
  1394. be a variable.
  1395.  
  1396. \Xi{\kwd{msgget} <key>\kwd{,} <flags>}
  1397. Creates a message queue for <key>.
  1398. Returns the message queue identifier.
  1399.  
  1400. \Xi{\kwd{msgsnd} <id>\kwd{,} <msg>\kwd{,} <flags>}
  1401. Sends <msg> to queue <id>.
  1402.  
  1403. \Xi{\kwd{msgrcv} <id>\kwd{,} \$<var>\kwd{,} <size>\kwd{,} <type>\kwd{,} <flags>}
  1404. Receives a message from queue <id> into <var>.
  1405.  
  1406. \Xi{\kwd{semctl} <id>\kwd{,} <semnum>\kwd{,} <cmd>\kwd{,} <arg>}
  1407. Calls {\it semctl\/}(2).\\
  1408. If <cmd> is |&IPC_STAT| of |&GETALL| then <arg> must 
  1409. be a variable.
  1410.  
  1411. \Xi{\kwd{semget} <key>\kwd{,} <nsems>\kwd{,} <size>\kwd{,} <flags>}
  1412. Creates a set of semaphores for <key>.
  1413. Returns the message semaphore identifier.
  1414.  
  1415. \Xi{\kwd{semop} <key>\kwd{,} ...}
  1416. Performs semaphore operations.
  1417.  
  1418. \Xi{\kwd{shmctl} <id>\kwd{,} <cmd>\kwd{,} <arg>}
  1419. Calls {\it shmctl\/}(2). If <cmd> is |&IPC_STAT| then <arg> must 
  1420. be a variable.
  1421.  
  1422. \Xi{\kwd{shmget} <key>\kwd{,} <size>\kwd{,} <flags>}
  1423. Creates shared memory.
  1424. Returns the shared memory segment identifier.
  1425.  
  1426. \Xi{\kwd{shmread} <id>\kwd{,} \$<var>\kwd{,} <pos>\kwd{,} <size>}
  1427. Reads at most <size> bytes of the contents of shared memory segment <id>
  1428. starting at offset <pos> into <var>.
  1429.  
  1430. \Xi{\kwd{shmwrite} <id>\kwd{,} <string>\kwd{,} <pos>\kwd{,} <size>}
  1431. Writes at most <size> bytes of <string> into the contents of 
  1432. shared memory segment <id> at offset <pos>.
  1433.  
  1434. \end{enum}
  1435.  
  1436.  
  1437. \section{Miscellaneous} 
  1438.  
  1439. \begin{enum}{1cm}
  1440.  
  1441. \Xi{\kwd{defined} <expr>}
  1442. Tests whether the lvalue <expr> has an actual value.
  1443.  
  1444. \Xi{\kwd{do} <filename>}
  1445. Executes <filename> as a Perl script.
  1446. See also \kwd{require} in section `Subroutines, packages and modules'.
  1447.  
  1448. \Xi{\kwd{dump} [ <label> ]}
  1449. Immediate core dump. When reincarnated, starts at <label>.
  1450.  
  1451. \Xi{\kwd{eval\{}<expr>\kwd{;} \ldots \}}
  1452. Executes the code between \{ and \}. Traps run-time errors as described
  1453. with \kwd{eval(}<expr>\kwd{)}, section `String~functions'.
  1454.  
  1455. \Xi{\kwd{local} <list>}
  1456. Creates a scope for the listed variables local to the enclosing block,
  1457. subroutine or eval. 
  1458.  
  1459. \Xi{\kwd{my} <list>}
  1460. Creates a scope for the listed variables lexically
  1461. local to the enclosing block, subroutine or eval. 
  1462.  
  1463. \Xi{\kwd{ref} \oEXPR}
  1464. Returns a \true{} value if <expr> is a reference.
  1465. Returns the package name if <expr> has been blessed into a package.
  1466.  
  1467. \Xi{\kwd{reset} [ <expr> ]}
  1468. Resets |??| searches so that they work again. <expr> is a list of
  1469. single letters. All variables and arrays beginning with one of those
  1470. letters are reset to their pristine state.  Only affects the current
  1471. package.
  1472.  
  1473. \Xi{\kwd{scalar} <expr> }
  1474. Forces evaluation of <expr> in scalar context.
  1475.  
  1476. \Xi{\kwd{undef} [ <lvalue> ]}
  1477. Undefines the <lvalue>. Always returns the undefined value.
  1478.  
  1479. \Xi{\kwd{wantarray}}
  1480. Returns \true{} if the current context expects an array value.
  1481.  
  1482. \end{enum}
  1483.  
  1484. \newpage
  1485.  
  1486. \section{Information from system files} 
  1487. See the manual about return values in scalar context.
  1488.  
  1489. {\largesl passwd} \\
  1490. Returns (\$name, \$passwd, \$uid, \$gid, \$quota, \$comment, \$gcos, \$dir, \$shell).
  1491.  
  1492. \begin{enum}{6cm}
  1493.  
  1494. \Xi{\kwd{endpwent}}
  1495. Ends look-up processing.
  1496.  
  1497. \Xi{\kwd{getpwent}}
  1498. Gets next user information.
  1499.  
  1500. \Xi{\kwd{getpwnam} <name>}
  1501. Gets information by name. 
  1502.  
  1503. \Xi{\kwd{getpwuid} <uid>}
  1504. Gets information by user ID.
  1505.  
  1506. \Xi{\kwd{setpwent}}
  1507. Resets look-up processing.
  1508.  
  1509. \end{enum}
  1510.  
  1511. {\vskip6pt\largesl group} \\
  1512. Returns (\$name, \$passwd, \$gid, \$members).
  1513.  
  1514. \begin{enum}{6cm}
  1515.  
  1516. \Xi{\kwd{endgrent}}
  1517. Ends look-up processing.
  1518.  
  1519. \Xi{\kwd{getgrgid} <gid>}
  1520. Gets information by group ID. 
  1521.  
  1522. \Xi{\kwd{getgrnam} <name>}
  1523. Gets information by name.
  1524.  
  1525. \Xi{\kwd{getgrent}}
  1526. Gets next group information.
  1527.  
  1528. \Xi{\kwd{setgrent}}
  1529. Resets look-up processing.
  1530.  
  1531. \end{enum}
  1532.  
  1533. {\vskip6pt\largesl hosts} \\
  1534. Returns (\$name, \$aliases, \$addrtype, \$length, @addrs).
  1535.  
  1536. \begin{enum}{6cm}
  1537.  
  1538. \Xi{\kwd{endhostent}}
  1539. Ends look-up processing.
  1540.  
  1541. \Xi{\kwd{gethostbyaddr} <addr>\kwd{,} <addrtype>}
  1542. Gets information by IP address.
  1543.  
  1544. \Xi{\kwd{gethostbyname} <name>}
  1545. Gets information by host name.
  1546.  
  1547. \Xi{\kwd{gethostent}}
  1548. Gets next host information.
  1549.  
  1550. \Xi{\kwd{sethostent} <stayopen>}
  1551. Resets look-up processing.
  1552.  
  1553. \end{enum}
  1554.  
  1555. {\vskip6pt\largesl networks} \\
  1556. Returns (\$name, \$aliases, \$addrtype, \$net).
  1557.  
  1558. \begin{enum}{6cm}
  1559.  
  1560. \Xi{\kwd{endnetent}}
  1561. Ends look-up processing.
  1562.  
  1563. \Xi{\kwd{getnetbyaddr} <addr>\kwd{,} <type>}
  1564. Gets information by address and type.
  1565.  
  1566. \Xi{\kwd{getnetbyname} <name>}
  1567. Gets information by network name.
  1568.  
  1569. \Xi{\kwd{getnetent}}
  1570. Gets next network information.
  1571.  
  1572. \Xi{\kwd{setnetent} <stayopen>}
  1573. Resets look-up processing.
  1574.  
  1575. \end{enum}
  1576.  
  1577. {\vskip6pt\largesl services} \\
  1578. Returns (\$name, \$aliases, \$port, \$proto).
  1579.  
  1580. \begin{enum}{6cm}
  1581.  
  1582. \Xi{\kwd{endservent}}
  1583. Ends look-up processing.
  1584.  
  1585. \Xi{\kwd{getservbyname} <name>\kwd{, }<proto>}
  1586. Gets information by service name. 
  1587.  
  1588. \Xi{\kwd{getservbyport} <port>\kwd{, }<proto>}
  1589. Gets information by service port.
  1590.  
  1591. \Xi{\kwd{getservent}}
  1592. Gets next service information.
  1593.  
  1594. \Xi{\kwd{setservent} <stayopen>}
  1595. Resets look-up processing.
  1596.  
  1597. \end{enum}
  1598.  
  1599. {\vskip6pt\largesl protocols} \\
  1600. Returns (\$name, \$aliases, \$proto).
  1601.  
  1602. \begin{enum}{6cm}
  1603.  
  1604. \Xi{\kwd{endprotoent}}
  1605. Ends look-up processing.
  1606.  
  1607. \Xi{\kwd{getprotobyname} <name>}
  1608. Gets information by protocol name.
  1609.  
  1610. \Xi{\kwd{getprotobynumber} <number>}
  1611. Gets information by protocol number.
  1612.  
  1613. \Xi{\kwd{getprotoent}}
  1614. Gets next protocol information.
  1615.  
  1616. \Xi{\kwd{setprotoent} <stayopen>}
  1617. Resets look-up processing.
  1618.  
  1619. \end{enum}
  1620.  
  1621.  
  1622. \section{Special variables} 
  1623.  
  1624. The following variables are global and should be localized in subroutines:
  1625.  
  1626. \begin{enum}{1cm}
  1627.  
  1628. \Xi{|\char`\$\char`\_|}
  1629. The default input and pattern-searching space.
  1630.  
  1631. \Xi{|\char`\$\char`\.|}
  1632. The current input line number of the last filehandle that was read.
  1633.  
  1634. \Xi{|\char`\$\char`\/|}
  1635. The input record separator, newline by default. May be multi-character.
  1636.  
  1637. \Xi{|\char`\$\char`\,|}
  1638. The output field separator for the print operator.
  1639.  
  1640. \Xi{|\char`\$\char`\"|}
  1641. The separator which joins elements of arrays interpolated in strings.
  1642.  
  1643. \Xi{|\char`\$\char`\\|}
  1644. The output record separator for the print operator.
  1645.  
  1646. \Xi{|\char`\$\char`\#|}
  1647. The output format for printed numbers. Deprecated.
  1648.  
  1649. \Xi{|\char`\$\char`\*|}
  1650. Set to 1 to do multiline matching within strings.
  1651. Deprecated, see the \kwd{m} and \kwd{s} modifiers in section 
  1652. `Search and replace functions'.
  1653.  
  1654. \Xi{|\char`\$\char`\?|}
  1655. The status returned by the last |`|\ldots|`| command, pipe \kwd{close} or
  1656. \kwd{system} operator. 
  1657.  
  1658. \Xi{|\char`\$\char`\]|}
  1659. The Perl version number, e.g. |5.001|.
  1660.  
  1661. \Xi{|\char`\$\char`\[|}
  1662. The index of the first element in an array, and of the first character
  1663. in a substring. Default is 0. Deprecated.
  1664.  
  1665. \Xi{|\char`\$\char`\;|}
  1666. The subscript separator for multi-dimensional array emulation. Default
  1667. is |"\034"|. 
  1668.  
  1669. \Xi{|\char`\$\char`\!|}
  1670. If used in a numeric context, yields the current value of |errno|. If
  1671. used in a string context, yields the corresponding error string. 
  1672.  
  1673. \Xi{|\char`\$\char`\@|}
  1674. The Perl error message from the last \kwd{eval} or \kwd{do} <expr> command.
  1675.  
  1676. \Xi{|\char`\$\char`\:|}
  1677. The set of characters after which a string may be broken to fill
  1678. continuation fields (starting with `|^|') in a format. 
  1679.  
  1680. \Xi{|\char`\$\char`\0|}
  1681. The name of the file containing the Perl script being executed. May be
  1682. assigned to. 
  1683.  
  1684. \Xi{|\char`\$\char`\$|}
  1685. The process number of the Perl interpreter running this script. Altered (in the
  1686. child process) by \kwd{fork}. 
  1687.  
  1688. \Xi{|\char`\$\char`\<|}
  1689. The real user ID of this process.
  1690.  
  1691. \Xi{|\char`\$\char`\>|}
  1692. The effective user ID of this process. 
  1693.  
  1694. \Xi{|\char`\$\char`\(|}
  1695. The real group ID of this process.
  1696.  
  1697. \Xi{|\char`\$\char`\)|}
  1698. The effective group ID of this process.
  1699.  
  1700. \Xi{|\char`\$\char`\^A|}
  1701. The accumulator for \kwd{formline} and \kwd{write} operations.
  1702.  
  1703. \Xi{|\char`\$\char`\^D|}
  1704. The debug flags as passed to Perl using `|-D|'.
  1705.  
  1706. \Xi{|\char`\$\char`\^F|}
  1707. The highest system file descriptor, ordinarily 2.
  1708.  
  1709. \Xi{|\char`\${\char`\^}I|}
  1710. In-place edit extension as passed to Perl using `|-i|'.
  1711.  
  1712. \Xi{|\char`\$\char`\^L|}
  1713. Formfeed character used in formats.
  1714.  
  1715. \Xi{|\char`\$\char`\^P|}
  1716. Internal debugging flag.
  1717.  
  1718. \Xi{|\char`\$\char`\^T|}
  1719. The time (as delivered by \kwd{time}) when the program started. This
  1720. value is used by the file test operators `|-M|', `|-A|' and `|-C|'.
  1721.  
  1722. \Xi{|\char`\$\char`\^W|}
  1723. The value of the `|-w|' option as passed to Perl.
  1724.  
  1725. \Xi{|\char`\$\char`\^X|}
  1726. The name by which this Perl interpreter was invoked.
  1727.  
  1728. \end{enum}
  1729.  
  1730. The following variables are context dependent and need not be
  1731. localized:
  1732.  
  1733. \begin{enum}{1cm}
  1734.  
  1735. \Xi{|\char`\$\char`\%|}
  1736. The current page number of the currently selected output channel.
  1737.  
  1738. \Xi{|\char`\$\char`\=|}
  1739. The page length of the current output channel. Default is 60 lines.
  1740.  
  1741. \Xi{|\char`\$\char`\-|}
  1742. The number of lines remaining on the page.
  1743.  
  1744. \Xi{|\char`\$\char`\~|}
  1745. The name of the current report format.
  1746.  
  1747. \Xi{|\char`\$\char`\^|}
  1748. The name of the current top-of-page format.
  1749.  
  1750. \Xi{|\char`\$\char`\||}
  1751. If set to nonzero, forces a flush after every write or print on the
  1752. output channel currently selected. Default is 0. 
  1753.  
  1754. \Xj{|\char`\$ARGV|}
  1755. The name of the current file when reading from |<|\,|>| .
  1756. \end{enum}
  1757.  
  1758. The following variables are always local to the current block:
  1759.  
  1760. \begin{enum}{1cm}
  1761.  
  1762. \Xi{|\char`\$\char`\&|}
  1763. The string matched by the last successful pattern match.
  1764.  
  1765. \Xi{|\char`\$\char`\`|}
  1766. The string preceding what was matched by the last successful match.
  1767.  
  1768. \Xi{|\char`\$\char`\'|}
  1769. The string following what was matched by the last successful match. 
  1770.  
  1771. \Xi{|\char`\$\char`\+|}
  1772. The last bracket matched by the last search pattern.
  1773.  
  1774. \Xj{\$|1|\ldots\$|9|\ldots}
  1775. Contain the subpatterns from the corresponding sets of parentheses in
  1776. the last pattern successfully matched.
  1777. |$10|\ldots and up are only available if the
  1778. match contained that many subpatterns. 
  1779.  
  1780. \end{enum}
  1781.  
  1782.  
  1783.  
  1784.  
  1785. \section{Special arrays} 
  1786.  
  1787. \begin{enum}{1.5cm}
  1788.  
  1789. \Xi{|@ARGV|}
  1790. Contains the command line arguments for the script (not including the command name).
  1791.  
  1792. \Xi{|@EXPORT|}
  1793. Names the methods a package exports by default.
  1794.  
  1795. \Xi{|@EXPORT\_OK|}
  1796. Names the methods a package can export upon explicit request.
  1797.  
  1798. \Xi{|@INC|}
  1799. Contains the list of places to look for Perl scripts to be evaluated
  1800. by the \kwd{do} <filename> and \kwd{require} commands. 
  1801.  
  1802. \Xi{|@ISA|}
  1803. List of \textit{base classes} of a package.
  1804.  
  1805. \Xi{|@\char`\_|}
  1806. Parameter array for subroutines. Also used by \kwd{split} if not in
  1807. array context. 
  1808.  
  1809. \Xi{|\char`\%ENV|}
  1810. Contains the current environment.
  1811.  
  1812. \Xi{|\char`\%INC|}
  1813. List of files that have been included with \kwd{require} or \kwd{do}.
  1814.  
  1815. \Xi{|\char`\%OVERLOAD|}
  1816. Can be used to overload operators in a package.
  1817.  
  1818. \Xi{|\char`\%SIG|}Used to set signal handlers for various signals.
  1819.  
  1820. \end{enum}
  1821.  
  1822.  
  1823. \section{Environment variables} 
  1824.  
  1825. Perl uses the following environment variables.
  1826.  
  1827. \begin{enum}{1.5cm}
  1828.  
  1829. \Xi{|HOME|}
  1830. Used if \kwd{chdir} has no argument.
  1831.  
  1832. \Xi{|LOGDIR|}
  1833. Used if \kwd{chdir} has no argument and |HOME| is not set.
  1834.  
  1835. \Xi{|PATH|}
  1836. Used in executing subprocesses, and in finding the Perl script if `|-S|'
  1837. is used.
  1838.  
  1839. \Xi{|PERL5LIB|}
  1840. A colon-separated list of directories to look in for Perl library files
  1841. before looking in the standard library and the current directory.
  1842.  
  1843. \Xi{|PERL5DB|}
  1844. The command to get the debugger code.
  1845. \newline Defaults to \hbox{|BEGIN { require 'perl5db.pl' }|}. 
  1846.  
  1847. \Xi{|PERLLIB|}
  1848. Used instead of |PERL5LIB| if the latter is not defined.
  1849.  
  1850. \end{enum}
  1851.  
  1852.  
  1853. \section{The perl debugger} 
  1854.  
  1855. The Perl symbolic debugger is invoked with `|perl -d|'.
  1856.  
  1857. \begin{enum}{2.5cm}
  1858.  
  1859. \Xi{|h|}
  1860. Prints out a help message.
  1861.  
  1862. \Xi{|T|}
  1863. Prints a stack trace.
  1864.  
  1865. \Xi{|s|}
  1866. Single steps.
  1867.  
  1868. \Xi{|n|}
  1869. Single steps around subroutine call.
  1870.  
  1871. \Xi{\fbox{<ret>}}
  1872. Repeats last `|s|' or `|n|'.
  1873.  
  1874. \Xi{|r|}
  1875. Returns from the current subroutine.
  1876.  
  1877. \Xi{|c| [ <line> ]}
  1878. Continues (until <line>, or another breakpoint, or exit).
  1879.  
  1880. \Xi{|p| \oEXPR}
  1881. Prints <expr>.
  1882.  
  1883. \Xi{|l| [ <range> ]}
  1884. Lists a range of lines. <range> may be a number, start--end,
  1885. start+amount, or a subroutine name. If omitted, lists next window. 
  1886.  
  1887. \Xi{|-|}
  1888. Lists previous window.
  1889.  
  1890. \Xi{|w|}
  1891. Lists window around current line.
  1892.  
  1893. \Xi{|f| <file>}
  1894. Switches to <file> and start listing it.
  1895.  
  1896. \Xi{|l| <sub>}
  1897. Lists the named <sub>routine.
  1898.  
  1899. \Xi{|S|}
  1900. List the names of all subroutines.
  1901.  
  1902. \Xi{|/|<pattern>|/|}
  1903. Searches forwards for <pattern>.
  1904.  
  1905. \Xi{|?|<pattern>|?|}
  1906. Searches backwards for <pattern>.
  1907.  
  1908. \Xi{|b| [ <line> [ <condition> ]]}
  1909. Sets breakpoint at <line>, default: current line.
  1910.  
  1911. \Xi{|b| <subname> [ <condition> ]}
  1912. Sets breakpoint at the subroutine.
  1913.  
  1914. \Xi{|d| [ <line> ]}
  1915. Deletes breakpoint at the given line.
  1916.  
  1917. \Xi{|D|}
  1918. Deletes all breakpoints.
  1919.  
  1920. \Xi{|L|}
  1921. Lists lines that have breakpoints or actions.
  1922.  
  1923. \Xi{|a| <line command>}
  1924. Sets an action for line.
  1925.  
  1926. \Xi{|A|}
  1927. Deletes all line actions.
  1928.  
  1929. \Xi{|\char`\<| <command>}
  1930. Sets an action to be executed before every debugger prompt.
  1931.  
  1932. \Xi{|\char`\>| <command>}
  1933. Sets an action to be executed before every `|s|', `|c|' or `|n|' command.
  1934.  
  1935. \Xi{|V| [ <package> [ <vars> ] ]}
  1936. Lists all variables in a package. Default package is main.
  1937.  
  1938. \Xi{|X| [ <vars> ]}
  1939. Like `|V|', but assumes the current package.
  1940.  
  1941. \Xi{|!| [ [-]<number> ]}
  1942. Re-executes a command. Default is the previous command.
  1943.  
  1944. \Xi{|H| [ -<number> ]}
  1945. Displays the last -<number> commands of more than one letter.
  1946.  
  1947. \Xi{|t|}
  1948. Toggles trace mode.
  1949.  
  1950. \Xi{|=|< > [ <alias value> ]}
  1951. Sets alias, or lists current aliases.
  1952.  
  1953. \Xi{|q|}
  1954. Quits. You may also use your \fbox{<eof>} character.
  1955.  
  1956. \Xi{<command>}
  1957. Executes <command> as a Perl statement.
  1958.  
  1959. \end{enum}
  1960.  
  1961. \newpage
  1962.  
  1963. \unnumbered{Notes}
  1964. \vfill
  1965. \makebox[\textwidth]{Perl Reference Guide Revision \refrev \hfill
  1966. \copyright 1989,1996 Johan Vromans}
  1967.  
  1968.  
  1969. \end{document}
  1970.